﻿using System;
using System.Windows;

namespace GroupChallenge.Helpers
{
    public class Utils
    {
        public static string GetHostUrl(bool withFinalSlash)
        {
            string ret = string.Empty;

            try
            {
                if (null != Application.Current)        // No app in design mode.
                {
                    ret = MainApp.Current.Host.Source.AbsoluteUri.ToLower();

                    ret = ret.Replace(MainApp.Current.Host.Source.AbsolutePath.ToLower(), string.Empty);

                    if (withFinalSlash)
                        ret += "/";
                }
            }
            catch (Exception ex)
            {
                if (null != Application.Current &&
                    null != MainApp.TheMainPage)        // No app in design mode.
                {
                    MessageBox.Show("Unable to get the host address.  Reason: " + ex.Message, "Host Address Error", MessageBoxButton.OK);
                }
            }

            return ret;
        }
    }
}
